home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / etsr301.zip / LPTX.ASM < prev    next >
Assembly Source File  |  1987-03-31  |  47KB  |  1,661 lines

  1. title LPTx : Line PrinTer Output Capture Routine
  2. page    60,132
  3. ;------------------------------------------------------------
  4. ;
  5. ;    MAIN PROGRAM    Version 6.00
  6. ;
  7. ;  (C)    Copyright 1987 by Mark DiVecchio, All Rights Reserved
  8. ;
  9. .xlist
  10. ;
  11. ;This program is released for use in non-commercial environments. I
  12. ;ask commercial users to register the program with a $25 copyright fee for
  13. ;each site (any number of users and computers) at which the program is used.
  14. ;
  15. ; DISCLAMER : this program tries to perform a function which is
  16. ; not supported by DOS. It will work sometime and will not work
  17. ; other times. That kind of explains why you don't see this type
  18. ; of program on the market.
  19. ; I have tested it under DOS 2.1 and DOS 3.1. Some users have
  20. ; reported trouble when running under DOS 3.x and for other users
  21. ; it works fine. USE AT YOUR OWN RISK.
  22. ;
  23. ; Mark C. DiVecchio
  24. ; 10435 Mountain Glen Terrace
  25. ; San Diego, CA 92131
  26. ; 619-566-6810
  27. ;------------------------------------------------------------
  28. ; Updates for Version 6.00        18 Mar 87
  29. ;
  30. ; Added use of Timer Interrupt and Idle interrupt to permit
  31. ; writing to disk
  32. ;
  33. ; Added a switch to inhibit the output of linefeed characters when
  34. ; capturing a file. Program strips linefeed character at the
  35. ; end of the line if you turn on this switch. The switch is -l on the
  36. ; command line when you open a capture file.
  37. ;
  38. ; This version does not use the PSP swapping of previous versions.
  39. ;
  40. ;------------------------------------------------------------
  41. ; Updates for Version 5.02        19 Nov 86
  42. ;
  43. ; Added -i inactivate option. Must be only option on command line :
  44. ;        lptx -i
  45. ;
  46. ; This version adds a check for DOS interuupt 21h
  47. ; function 40h for standard printer device = 0004.
  48. ;
  49. ; This addition was suggested by Dale Letterman of Seattle.
  50. ;
  51. ; Assembled using MicroSoft MASM v 4.0
  52. ;
  53. ; Program is called and used in the same way as version 3.00
  54. ;
  55. ; I now enter DOS with interrupts disabled.
  56. ;
  57. ; Added a switch to inhibit the checking of the Critical Section Flag
  58. ; Add -x to the command line the first time that you run LPTx.
  59. ;
  60. ;------------------------------------------------------------
  61. ; Updates for Version 5.00        13 May 86
  62. ;
  63. ; This version also takes over the DOS interuupt 21h and specifically
  64. ; checks for function 5.
  65. ; If that is the call, LPTx captures the character if LPTx has been
  66. ; activated. If it is a DOS call, LPTx assumes that DOS wants LPT1 since
  67. ; there is no way for the DOS call to specify a line printer number.
  68. ;
  69. ; Uses undocumented DOS int 21h calls 50h and 51h.
  70. ;    50h    Set new current Program Segment Prefix(PSP) from
  71. ;        segment number in BX
  72. ;    51h    Get current PSP into BX.
  73. ; These calls are used before any file is opened by the resident portion
  74. ; of LPTx. There is some concern that DOS puts information about open files
  75. ; into the current PSP. Before we open our spooler file, we want to set
  76. ; the current PSP to our PSP and then restore it after the file I/O
  77. ; is complete. This idea was expressed in PC Magazine May 13, 1986 on page
  78. ; 314 in an article by Charles Petzold.
  79. ;
  80. ;
  81. ; This version 5.0 does not obsolete versions 4.0 and 3.0. Those versions
  82. ; may work under some conditions where this one does not and vica versa.
  83. ;------------------------------------------------------------
  84. ; Updates for Version 4.01        5 May 86
  85. ;
  86. ; Had an error in the way LPTx detected if it was already in memory.
  87. ; This error existed from back in version 3.00 and may have been
  88. ; the cause of this program locking up the system the very first
  89. ; time it was called.
  90. ;------------------------------------------------------------
  91. ; Updates for Version 4.0        25 April 86
  92. ;
  93. ; Assembled using MicroSoft MASM v 4.0
  94. ;
  95. ; Program is called and used in the same way as version 3.00
  96. ;
  97. ; Modified the code to check if DOS was running when the print interrupt
  98. ; occurs. If so the print request is routed back to the regular line
  99. ; printer. This will limit the use of this capture program to user
  100. ; programs which do their own output without going to DOS.
  101. ;
  102. ; In turn, this guarantees that we do re-enter DOS.
  103. ;
  104. ; The trick of saving the DOS stack was dropped in this version and
  105. ; I have resorted to another trick which I garnered from the
  106. ; following message found on info-ibmpc. I use method number 2.
  107. ;
  108. ; This version 4.0 does not obsolete version 3.0. That version may
  109. ; work under some conditions where this one does not and vica versa.
  110. ; This one worked fine for me using DOS 2.1 and 123 version 1.A.
  111. ; Will not work with Shift PrtSc.
  112. ;
  113. comment *
  114. Date: Thu, 30 Jan 86 08:47:51 est
  115. Subject: File I/O from resident programs
  116. To: allegra!seismo!usc-isib.arpa!info-ibmpc
  117.  
  118. Regarding opening up a file when you are terminate-and-stay-resident:
  119.  
  120. Be very careful when you attempt this.  Many an FAT has been eaten for
  121. lunch when I first tried doing it.  Two ways that work like a charm:
  122.  
  123. 1)    Take over interrupt 0x28.  This interrupt gets called by DOS
  124.     while its waiting for a key to be hit. Whenever it does get
  125.     called (your program should not be time critical, btw, as
  126.     this routine is never called from CPU intensive tasks), it
  127.     is safe to do with DOS what you will. (Except for certain
  128.     interruptions, such as Search First and Search Next, which
  129.     either you'll screw-up for the foreground task, or they'll
  130.     screw-up for you.)
  131.  
  132. 2)    Get the Critical Section Flag by issuing an int 21, with ah=0x34.
  133.     This returns a pointer to a flag in ES:BX. When this flag is
  134.     NULL, and interrupts are on, it is safe to play DOS games.
  135.     Unless you are the last program to take over the interrupt,
  136.     don't trust the flag word: many "fine" programs like SideKick
  137.     do not give you a true copy of the flag word on the stack, but
  138.     rather give a simple "pushf" after interrupts are turned off.
  139. * ;end of comment
  140. ;
  141. ; More information from a message posted on USENIX:
  142. ;
  143. comment *
  144. From sdcsvax!ihnp4!timeinc!greenber Mon Jul  1 05:12:16 1985
  145. Date: 30 Jun 85 17:12:37 CDT (Sun)
  146. -----------------------------------------------------------
  147. INT 21 - Internal - Return CritSectFlag Pointer (MSDOS generic)
  148.       REG AH = 34H
  149.       On Return:
  150.             ES:BX points to DOS "Critical Section Flag"
  151.       When byte pointed to is zero, DOS is supposed to be
  152.       safe to interrupt. NOT RELIABLE according to Chris
  153.       Dunford.
  154.             Examination of DOS 2.10 code in this area
  155.       indicates that the byte immediately FOLLOWING this
  156.       "Critical Section Flag" must be 00 to permit the
  157.       PRINT.COM interrupt to be called. This suggests that
  158.       checking the WORD pointed to, rather than the BYTE,
  159.       might increase reliability of the test greatly.
  160. -----------------------------------------------------------
  161. INT 28 - Internal routine for MSDOS
  162.       This interrupt is called from inside the "get input
  163. from keyboard" routine in DOS, if and only if it is safe to use
  164. INT 21 to access the disk at that time. It is used primarily by
  165. the PRINT.COM routines, but any number of other routines could
  166. be chained to it by saving the original vector, and calling it
  167. with a FAR call (or just JMPing to it) at the end of the new
  168. routine.
  169.       Until PRINT.COM installs its own routine, this
  170. interrupt vector simply points to an IRET opcode.
  171. -----------------------------------------------------------
  172. * ;end of comment
  173. ;
  174. ;------------------------------------------------------------
  175. ; Updates for Version 3.0
  176. ;
  177. ; This version is fully compatible with IBM's PRINT command and
  178. ; hopefully most other print spoolers. I changed the method by which
  179. ; LPTx determines if a resident copy of itself is already in memory.
  180. ;
  181. ;------------------------------------------------------------
  182. ; This program intercepts the BIOS interrupt 17, the line printer
  183. ; interrupt. It will redirect the output of LPT1, LPT2, or LPT3 to a disk
  184. ; file. All three redirects may be active at the same time.
  185. ;
  186. ;
  187. ; Background:
  188. ;
  189. ; The basic problem with this type of program is that PC-DOS as written
  190. ; by Microsoft is not re-entrant. That means that if DOS is in control when
  191. ; the print interrupt occurs, you can not call DOS again to do some other
  192. ; function. Therefore, LPTx can no